<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">
<head>
<link rel="stylesheet"  href="/layui/css/layui.css"/>
<meta charset="UTF-8">
<meta name="renderer" content="webkit">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
<title>添加产品</title>
</head>
<body>
<script src="/plugins/jquery/jquery-1.10.2.min.js"></script>
<script  src="/layui/layui.js"></script>
<script src="/plugins/js/common.js"></script>
<form class="layui-form" action="/product/addProduct" id="saveForm">
	<br>
  <input type="hidden" id="attachmentId" name="attachmentId">	
  <div class="layui-form-item">
	    <div class="layui-inline">
	      <label class="layui-form-label">产品名称：</label>
	      <div class="layui-input-inline">
	        <input  name="name" placeholder="请输入产品名称" lay-verify="required" style="width: 260px;" autocomplete="off" class="layui-input">
	      </div>
	    </div>
  </div>
  <div class="layui-form-item">
	    <div class="layui-inline">
	      <label class="layui-form-label">标题：</label>
	      <div class="layui-input-inline">
	        <input  name="productTitle" placeholder="请输入产品标题" lay-verify="required" style="width: 300px;" autocomplete="off" class="layui-input">
	      </div>
	    </div>
  </div>
  <div class="layui-form-item">
	    <div class="layui-inline">
	      <label class="layui-form-label">保障金额：</label>
	      <div class="layui-input-inline">
	        <input  name="amountProtection" placeholder="￥" lay-verify="required|number"  autocomplete="off" class="layui-input">
	      </div>
	    </div>
  </div>
  <div class="layui-form-item">
	    <div class="layui-inline">
	      <label class="layui-form-label">申请金额：</label>
	      <div class="layui-input-inline">
	        <input  name="applyAmount" placeholder="￥" lay-verify="required|number"  autocomplete="off" class="layui-input">
	      </div>
	    </div>
  </div>
  <div class="layui-form-item">
    <label class="layui-form-label">申请用户类型：</label>
     <div class="layui-input-block">
      <input type="radio" name="applyUserType"  lay-verify="required" value="1" title="VIP用户">
      <input type="radio" name="applyUserType"  lay-verify="required" value="2" title="所有用户">
    </div>
  </div>
  <div class="layui-form-item">
	    <div class="layui-inline">
	      <label class="layui-form-label">备注：</label>
	      <div class="layui-input-block">
	       <textarea placeholder="请输入备注信息" class="layui-textarea" cols="80"></textarea>
	      </div>
	    </div>
  </div>
  <div class="layui-form-item">
	    <div class="layui-inline">
	      <label class="layui-form-label">加入条件：</label>
	      <div class="layui-input-block">
	       <textarea id="joinCondition" name="joinCondition" style="display: none;"></textarea>
	      </div>
	    </div>
  </div>
  <div class="layui-form-item">
	    <div class="layui-inline">
	      <label class="layui-form-label">点击“187天”：</label>
	      <div class="layui-input-block">
	       <textarea id="click187Days" style="display: none;"></textarea>
	      </div>
	    </div>
  </div>
  <div class="layui-form-item">
	    <div class="layui-inline">
	      <label class="layui-form-label">健康要求：</label>
	      <div class="layui-input-block">
	       <textarea id="clickHealthDemand"  style="display: none;"></textarea>
	      </div>
	    </div>
  </div>
   <div class="layui-form-item">
	    <div class="layui-inline">
	      <label class="layui-form-label">常见问题：</label>
	      <div class="layui-input-block">
	       <textarea id="commonProblem"  style="display: none;"></textarea>
	      </div>
	    </div>
  </div>
  <div class="layui-form-item">
	    <div class="layui-inline">
	      <label class="layui-form-label">均摊规则：</label>
	      <div class="layui-input-block">
	       <textarea id="equalizationRule"  style="display: none;"></textarea>
	      </div>
	    </div>
  </div>
  <div class="layui-form-item">
	    <div class="layui-inline">
	      <label class="layui-form-label">计划章程：</label>
	      <div class="layui-input-block">
	       <textarea id="planCharter"  style="display: none;"></textarea>
	      </div>
	    </div>
  </div>
  <div class="layui-form-item">
	    <div class="layui-inline">
	      <label class="layui-form-label">延续条件：</label>
	      <div class="layui-input-block">
	       <textarea id="continueCondition"  style="display: none;"></textarea>
	      </div>
	    </div>
  </div>
  <div class="layui-form-item">
	    <div class="layui-inline">
	      <label class="layui-form-label">最高可获得互助：</label>
	      <div class="layui-input-block">
	       <textarea id="maxMutualAssistance"  style="display: none;"></textarea>
	      </div>
	    </div>
  </div>
  <div class="layui-form-item">
	    <div class="layui-inline">
	      <label class="layui-form-label">计划涵盖：</label>
	      <div class="layui-input-block">
	       <textarea id="planCoverage"  style="display: none;"></textarea>
	      </div>
	    </div>
  </div>
  <div class="layui-form-item">
	    <div class="layui-inline">
	      <label class="layui-form-label">服务费用：</label>
	      <div class="layui-input-block">
	       <textarea id="serviceFee"  style="display: none;"></textarea>
	      </div>
	    </div>
  </div>
  <div class="layui-form-item">
	    <div class="layui-inline">
	      <label class="layui-form-label">会员公约：</label>
	      <div class="layui-input-block">
	       <textarea id="memberConvention"  style="display: none;"></textarea>
	      </div>
	    </div>
  </div>
  <fieldset class="layui-elem-field layui-field-title" style="margin-top: 30px;">
  <legend>请上传产品图片</legend>
</fieldset>
<div class="layui-upload">
  <button type="button" class="layui-btn" id="test1">上传图片</button>
  <div class="layui-upload-list">
    <img class="layui-upload-img" id="demo1">
    <p id="demoText"></p>
  </div>
</div>   
  <div class="layui-form-item">
    <div class="layui-input-block">
      <button class="layui-btn" lay-submit="" lay-filter="saveProduct">立即提交</button>
      <button type="reset" class="layui-btn layui-btn-primary">重置</button>
    </div>
  </div>
</form>
<script type="text/javascript">
layui.use(['layedit','upload','form'], function(){
	 var layedit = layui.layedit;
	 var joinConditionIndex = layedit.build('joinCondition'); //建立编辑器
	 var click187DaysIndex = layedit.build('click187Days'); //建立编辑器
	 var clickHealthDemandIndex = layedit.build('clickHealthDemand'); //建立编辑器
	 
	 var commonProblemIndex = layedit.build('commonProblem'); //建立编辑器
	 var equalizationRuleIndex = layedit.build('equalizationRule'); //建立编辑器
	 var planCharterIndex = layedit.build('planCharter'); //建立编辑器
	 
	 var continueConditionIndex = layedit.build('continueCondition'); //建立编辑器
	 var maxMutualAssistanceIndex = layedit.build('maxMutualAssistance'); //建立编辑器
	 var planCoverageIndex = layedit.build('planCoverage'); //建立编辑器
	 var serviceFeeIndex = layedit.build('serviceFee'); //建立编辑器
	 var memberConventionIndex = layedit.build('memberConvention'); //建立编辑器
	 
	 upload = layui.upload;
	 form = layui.form;
	 form.on('submit(saveProduct)', function(data){
		 data.field.joinCondition=layedit.getContent(joinConditionIndex);
		 data.field.click187Days=layedit.getContent(click187DaysIndex);
		 data.field.clickHealthDemand=layedit.getContent(clickHealthDemandIndex);
		 
		 data.field.commonProblem=layedit.getContent(commonProblemIndex);
		 data.field.equalizationRule=layedit.getContent(equalizationRuleIndex);
		 data.field.planCharter=layedit.getContent(planCharterIndex);
		 
		 data.field.continueCondition=layedit.getContent(continueConditionIndex);
		 data.field.maxMutualAssistance=layedit.getContent(maxMutualAssistanceIndex);
		 data.field.planCoverage=layedit.getContent(planCoverageIndex);
		 data.field.serviceFee=layedit.getContent(serviceFeeIndex);
		 data.field.memberConvention=layedit.getContent(memberConventionIndex);
		 
		  $.ajax({
              url: "/product/addProduct",
              data: data.field,
              type: "post",
              success: function (result) {
            	if(result.status==1){
            		parent.search("添加成功");
                	var index = parent.layer.getFrameIndex(window.name);
                	setTimeout(function(){parent.layer.close(index)}, 1000);
            	}else{
            		layMsg("添加失败",2000);
            	}
              },
              error: function (result) {
            	  layMsg("请求异常",2000);
              }
		});
	return false;	  
	});
	 
	//普通图片上传
	  var uploadInst = upload.render({
	    elem: '#test1'
	    ,url: '/uploadImg'
	    ,before: function(obj){
	      //预读本地文件示例，不支持ie8
	      obj.preview(function(index, file, result){
	        $('#demo1').attr('src', result); //图片链接（base64）
	      });
	    }
	    ,done: function(res){
	      //如果上传失败
	      if(res.status == 2){
	        return layer.msg('上传失败');
	      }else{
	    	$("#attachmentId").val(res.data);
	    	return layer.msg('上传成功');
	      }
	      //上传成功
	    }
	    ,error: function(){
	      //演示失败状态，并实现重传
	      var demoText = $('#demoText');
	      demoText.html('<span style="color: #FF5722;">上传失败</span> <a class="layui-btn layui-btn-xs demo-reload">重试</a>');
	      demoText.find('.demo-reload').on('click', function(){
	        uploadInst.upload();
	      });
	    }
	  });
});


</script>
</body>
</html>